package com.itic.mall.mobile.index;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.applications.sys.code.persistence.model.CodeDetail;
import com.itic.appbase.applications.sys.code.vo.CodeDetailVo;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.utils.NumberStringHelper;
import com.itic.appbase.framework.utils.RandomStringHelper;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.system.banner.persistence.model.Banner;
import com.itic.mall.system.banner.persistence.model.BannerExample;
import com.itic.mall.system.banner.service.BannerService;
import com.itic.mall.system.category.persistence.model.Category;
import com.itic.mall.system.category.persistence.model.CategoryExample;
import com.itic.mall.system.category.service.CategoryService;
import com.itic.mall.system.product.persistence.model.Product;
import com.itic.mall.system.product.persistence.model.ProductExample;
import com.itic.mall.system.product.persistence.model.ProductExample.Criteria;
import com.itic.mall.system.product.service.ProductService;
import com.itic.mall.system.productjd.persistence.model.ProductJd;
import com.itic.mall.system.productjd.persistence.model.ProductJdExample;
import com.itic.mall.system.productsku.persistence.model.ProductSku;
import com.itic.mall.system.productsku.persistence.model.ProductSkuExample;
import com.itic.mall.system.productsku.service.ProductSkuService;
import com.itic.mall.system.weixinbatch.persistence.model.WeixinBatch;
import com.itic.mall.system.weixinbatch.persistence.model.WeixinBatchExample;
import com.itic.mall.system.weixinbatch.service.WeixinBatchService;


/**
 * 友惠家商城中心接口类
 * @author 许小宝
 * 2017年07月25日  14时11分
 */
@Controller
@RequestMapping(value="/mobile/index")
public class MallIndexInterface
     extends BaseMobileInterface {
   @Autowired
   private ProductService productService;
   @Autowired
   private ProductSkuService productSkuService;
   @Autowired
   private CategoryService categoryService;
   @Autowired
   private BannerService bannerService;
   @Autowired
   private WeixinBatchService weixinBatchService;
   
   
   /**
    * APP用户登入商城中心首页
    * @return
    */
   @RequestMapping(value="/list")
   @ResponseBody
   public Map<String,Object> list( HttpServletRequest request,HttpServletResponse response,String keyword, String id ){
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	   	String result = FAIL;
	   	String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	try{
	   		
	   		List<ProductAndJd> projds = new ArrayList<ProductAndJd>();
	   		
	   		if( StringHelper.isNotBlank(id) ){
	   			WeixinBatch vo = weixinBatchService.get(id);
    			if( null != vo ){
    				String productJdIds = vo.getProductJdIds();
    				projds = getProductJdByIds(projds, productJdIds);
    				
    				String productIds = vo.getProductIds();
    				projds = getProductByIds(projds, productIds);
    				
    			}
    			resultMap.put(DATA, projds);
    			
	   		}else{
	   			ProductJdExample example2 = new ProductJdExample();
		   		example2.setOrderByClause("UPDATE_TIME DESC");
		   		example2.setOrderByClause("JINGXUAN_ORDER ASC");
		   		//handlePageQueryDefault(request, example2);example.setOrderByClause("UPDATE_TIME DESC");
		   		com.itic.mall.system.productjd.persistence.model.ProductJdExample.Criteria criteria2 = example2.createCriteria();
		   		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
		   		if( StringHelper.isNotBlank(keyword) ){
		   			criteria2.andGoodsNameLike("%"+keyword+"%");
		   		}else{
		   			criteria2.andIsJingxuanEqualTo("001");
		   		}
		   		List<ProductJd> jds = productJdService.list(example2);
		   		if( jds.size()>0 ){
		   			for( ProductJd temp : jds ){
		   				ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getGoodsUrl());
		   				projd.setName(temp.getGoodsName());
		   				projd.setProductHongbao(temp.getConTicketPrice());
		   				projd.setProductOrginPrice(temp.getOriPrice());
		   				projd.setProductPrice(temp.getConPrice());
		   				projd.setTotalFeedback(RandomStringHelper.randomNumStr(3));
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("002");
		   				projds.add(projd);
		   			}
		   		}
		   		
		   		ProductExample example = new ProductExample();
		   		example.setOrderByClause("UPDATE_TIME DESC");
		   		example.setOrderByClause("REORDER ASC");
		   		//handlePageQueryDefault(request, example);
		   		Criteria criteria = example.createCriteria();
		   		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		   		if( StringHelper.isNotBlank(keyword) ){
		   			criteria.andNameLike("%"+keyword+"%");
		   		}else{
		   			criteria2.andIsJingxuanEqualTo("001");
		   		}
		   		List<Product> products = productService.list(example);
		   		if( products.size()>0 ){
		   			for( Product temp : products ){
		   				ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getMainImageUrl());
		   				projd.setName(temp.getName());
		   				projd.setProductHongbao(temp.getProductHongbao());
		   				projd.setProductOrginPrice(temp.getProductOrginPrice());
		   				projd.setProductPrice(temp.getProductPrice());
		   				projd.setTotalFeedback(temp.getTotalFeedback());
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("001");
		   				projds.add(projd);
		   			}
		   		}
	   		}
	   		resultMap.put(DATA, projds);
	   		result = SUCCESS;
	   		errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	   		
	   	}catch(Exception e){
	   		errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("MallIndexInterface", "list", e.toString(),"商品搜索",e);
			
	   	}
	   	resultMap.put(RESULT, result);
	   	resultMap.put(ERROR_CODE, errorCode);
	   	resultMap.put(ERROR_MSG, errorMsg);
	   	isCrrossDomain(response);
	   	return resultMap;
   }
   
   /**
    * APP用户登入商城中心首页
    * @return
    */
   @RequestMapping(value="/listkeyword")
   @ResponseBody
   public Map<String,Object> listkeyword( HttpServletRequest request,HttpServletResponse response,String keyword, String id ){
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	   	String result = FAIL;
	   	String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	   	try{
	   		
	   		List<ProductAndJd> projds = new ArrayList<ProductAndJd>();
	   		
	   		if( StringHelper.isNotBlank(id) ){
	   			WeixinBatch vo = weixinBatchService.get(id);
    			if( null != vo ){
    				String productJdIds = vo.getProductJdIds();
    				projds = getProductJdByIds(projds, productJdIds);
    				
    				String productIds = vo.getProductIds();
    				projds = getProductByIds(projds, productIds);
    				
    			}
    			resultMap.put(DATA, projds);
    			
	   		}else{
	   			ProductJdExample example2 = new ProductJdExample();
		   		example2.setOrderByClause("UPDATE_TIME DESC");
		   		example2.setOrderByClause("JINGXUAN_ORDER ASC");
		   		//handlePageQueryDefault(request, example2);example.setOrderByClause("UPDATE_TIME DESC");
		   		com.itic.mall.system.productjd.persistence.model.ProductJdExample.Criteria criteria2 = example2.createCriteria();
		   		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
		   		//criteria2.andIsJingxuanEqualTo("001");
		   		if( StringHelper.isNotBlank(keyword) ){
		   			criteria2.andGoodsNameLike("%"+keyword+"%");
		   		}
		   		List<ProductJd> jds = productJdService.list(example2);
		   		if( jds.size()>0 ){
		   			for( ProductJd temp : jds ){
		   				ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getGoodsUrl());
		   				projd.setName(temp.getGoodsName());
		   				projd.setProductHongbao(temp.getConTicketPrice());
		   				projd.setProductOrginPrice(temp.getOriPrice());
		   				projd.setProductPrice(temp.getConPrice());
		   				projd.setTotalFeedback(RandomStringHelper.randomNumStr(3));
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("002");
		   				projds.add(projd);
		   			}
		   		}
		   		
		   		ProductExample example = new ProductExample();
		   		example.setOrderByClause("UPDATE_TIME DESC");
		   		example.setOrderByClause("REORDER ASC");
		   		//handlePageQueryDefault(request, example);
		   		Criteria criteria = example.createCriteria();
		   		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		   		//criteria.andIsJingpingEqualTo("001");
		   		if( StringHelper.isNotBlank(keyword) ){
		   			criteria.andNameLike("%"+keyword+"%");
		   		}
		   		List<Product> products = productService.list(example);
		   		if( products.size()>0 ){
		   			for( Product temp : products ){
		   				ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getMainImageUrl());
		   				projd.setName(temp.getName());
		   				projd.setProductHongbao(temp.getProductHongbao());
		   				projd.setProductOrginPrice(temp.getProductOrginPrice());
		   				projd.setProductPrice(temp.getProductPrice());
		   				projd.setTotalFeedback(temp.getTotalFeedback());
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("001");
		   				projds.add(projd);
		   			}
		   		}
	   		}
	   		resultMap.put(DATA, projds);
	   		result = SUCCESS;
	   		errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	   		
	   	}catch(Exception e){
	   		errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("MallIndexInterface", "list", e.toString(),"商品搜索",e);
			
	   	}
	   	resultMap.put(RESULT, result);
	   	resultMap.put(ERROR_CODE, errorCode);
	   	resultMap.put(ERROR_MSG, errorMsg);
	   	isCrrossDomain(response);
	   	return resultMap;
   }
   
   

   
   /**
    * 判断商品的销量是否大于库存
    * @return
    */
   @RequestMapping(value="/isNone")
   @ResponseBody
   public Map<String,Object> isNone(HttpServletRequest request,HttpServletResponse response,String id){
   	Map<String, Object> resultMap = new HashMap<String,Object>();
   	String result = FAIL;
   	String errorCode = PARAM_ERROR_CODE;
   	String errorMsg = PARAM_ERROR_MSG;
   	try{
   		String isNone = "have";
   		if( StringHelper.isNotBlank(id) ){
   			Product product = productService.get(id);
   			if( null != product ){
   				String totalSales = product.getTotalSales();
   				ProductSkuExample example = new ProductSkuExample();
   				com.itic.mall.system.productsku.persistence.model.ProductSkuExample.Criteria criteria = example.createCriteria();
   				criteria.andIsEffectiveEqualTo(DBConst.TRUE);
   				criteria.andProductIdEqualTo(id);
   				List<ProductSku> list = productSkuService.list(example);
   				String inventory = "0";
   			    if( list.size()>0 ){
   			    	for( ProductSku temp: list ){
   			    		String productInventory = temp.getProductInventory();
   			    		inventory = NumberStringHelper.addString(inventory, productInventory);
   			    	}
   			    }
   			    
   			    //如果销量大于库存或等于库存数量，代表已卖完了
   			    if( NumberStringHelper.isGreater(totalSales, inventory) ){
   			    	isNone = "none";
   			    }
   			}
   		}
   		resultMap.put(DATA, isNone);
   		result = SUCCESS;
   		errorCode = SUCCESS_ERROR_CODE;
       	errorMsg = SUCCESS_ERROR_MSG;
   		
   	}catch(Exception e){
   		errorCode = SERVER_ERROR_CODE;
       	errorMsg = SERVER_ERROR_MSG;
   		logException("MallIndexInterface", "isNone", e.toString(),"判断秒杀是否存在",e);
		
   	}
   	resultMap.put(RESULT, result);
   	resultMap.put(ERROR_CODE, errorCode);
   	resultMap.put(ERROR_MSG, errorMsg);
   	isCrrossDomain(response);
   	return resultMap;
   } 
   
   
    /**
     * APP用户登入商城中心首页
     * @return
     */
    @RequestMapping(value="/banners")
    @ResponseBody
    public Map<String,Object> banners(HttpServletRequest request,HttpServletResponse response,String type){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		BannerExample example = new BannerExample();
    		example.setOrderByClause("CREATE_TIME");
    		example.setOrderByClause("REORDER ASC");
    		com.itic.mall.system.banner.persistence.model.BannerExample.Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    		if( StringHelper.isNotBlank(type) ){
    			criteria.andTypeEqualTo(type);
    		}else{
    			criteria.andTypeEqualTo("001");
    		}
    		List<Banner> list = bannerService.list(example);
    		resultMap.put(DATA, list);
    		result = SUCCESS;
    		errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
    		logException("MallIndexInterface", "index", e.toString(),"登入商城中心首页",e);
		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    } 
    
    /**
     * APP用户登入商城中心首页
     * @return
     */
    @RequestMapping(value="/bannerDetail")
    @ResponseBody
    public Map<String,Object> bannerDetail(HttpServletRequest request,HttpServletResponse response,String id ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{ 
    		
    		if( StringHelper.isNotBlank(id) ){
    			
    			Map<String, Object> dataMap = new HashMap<String,Object>();
    			Banner banner = bannerService.get(id);
    			dataMap.put("banner", banner);
    			
    			if( null != banner ){
    				String note = banner.getNote();
        			String[] split = note.split(",");
        			
        			List<String> list = new ArrayList<String>();
        			
        			for( int i=0 ; i<split.length; i++ ){
        				list.add(split[i]);
        			}
        			
        			ProductExample example = new ProductExample();
        			this.handlePageQuery(request, example);
        			example.setOrderByClause("CREATE_TIME DESC");
        			example.setOrderByClause("REORDER ASC");
        			example.createCriteria().andIdIn(list);
        			int count = productService.count(example);
        			List<Product> products = productService.list(example);
        			if( products.size() > 0 ){
                		for( Product tmp: products ){
                			filterPrice(tmp);
                		}
                	}
        			dataMap.put("products", products);
        			dataMap.put("count", count);
        			resultMap.put(DATA, dataMap);
    			}
    			
    			result = SUCCESS;
        		errorCode = SUCCESS_ERROR_CODE;
            	errorMsg = SUCCESS_ERROR_MSG;
            	
    		}
    		
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
    		logException("MallIndexInterface", "index", e.toString(),"登入商城中心首页",e);
		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    } 
    
    
    
    /**
     * APP用户登入商城中心首页
     * @return
     */
    @RequestMapping(value="/seckillTime")
    @ResponseBody
    public Map<String,Object> seckillTime(HttpServletRequest request,HttpServletResponse response){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		CodeDetailVo vo = new CodeDetailVo();
    		vo.setType("T_DM_MALL_SECKILL_TIME");
    		
    		List<CodeDetail> list = outCommonService.getCodeDetail(vo);
    		
    		resultMap.put(DATA, list);
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
    		logException("MallIndexInterface", "index", e.toString(),"登入商城中心首页",e);
		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    } 
    
    
    /**
     * APP用户登入商城中心首页
     * @return
     */
    @RequestMapping(value="/seckills")
    @ResponseBody
    public Map<String,Object> seckillTime(HttpServletRequest request,HttpServletResponse response,String type){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		if( StringHelper.isNotBlank(type) ){
    			//根据条件查找相应 的商品信息
        		ProductExample example = new ProductExample();
        		Criteria criteria = example.createCriteria();
        		example.setOrderByClause("CREATE_TIME DESC");
        		example.setOrderByClause("SECKILL_ORDER ASC");
        		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
        		criteria.andSeckillTypeEqualTo(type);
        		
        		List<Product> list = productService.list(example);
        		if( list.size() > 0 ){
            		for( Product tmp: list ){
            			tmp.setProductPrice(tmp.getSeckillPrice());
            		}
            	}
        		
            	resultMap.put(DATA, list);
    			result = SUCCESS;
    			errorCode = SUCCESS_ERROR_CODE;
            	errorMsg = SUCCESS_ERROR_MSG;  	
    		}
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
    		logException("MallIndexInterface", "index", e.toString(),"登入商城中心首页",e);
		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    } 
    
    
    
    
    
    
    /**
     * 登入折扣商城中心首页
     * @param categoryId 类别ID
     * @param orderType 排序类型
     * @param minMaxPrice 最小到最大的价格区间，中间用-号相隔
     * @param minMaxPrice 最小到最大的销量区间     中间用-号相隔
     * @return
     */
    @RequestMapping(value="/baokuans")
    @ResponseBody
    public Map<String,Object> baokuans(HttpServletRequest request,HttpServletResponse response){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		List<ProductAndJd> projds = new ArrayList<ProductAndJd>();
	   		
	   		
	   		ProductJdExample example2 = new ProductJdExample();
	   		example2.setOrderByClause("UPDATE_TIME DESC");
	   		example2.setOrderByClause("ORDER_BAOKUAN ASC");
	   		handlePageQueryDefault(request, example2);
	   		com.itic.mall.system.productjd.persistence.model.ProductJdExample.Criteria criteria2 = example2.createCriteria();
	   		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
	   		criteria2.andIsBaokuanEqualTo("001");
	   		
	   		List<ProductJd> jds = productJdService.list(example2);
	   		if( jds.size()>0 ){
	   			for( ProductJd temp : jds ){
	   				ProductAndJd projd = new ProductAndJd();
	   				projd.setId(temp.getId());
	   				projd.setMainImageUrl(temp.getGoodsUrl());
	   				projd.setName(temp.getGoodsName());
	   				projd.setProductHongbao(temp.getConTicketPrice());
	   				projd.setProductOrginPrice(temp.getOriPrice());
	   				projd.setProductPrice(temp.getConPrice());
	   				projd.setTotalFeedback(RandomStringHelper.randomNumStr(3));
	   				projd.setTotalSales(temp.getTotalSales());
	   				projd.setType("002");
	   				projds.add(projd);
	   			}
	   		}
	   		
	   		ProductExample example = new ProductExample();
	   		example.setOrderByClause("UPDATE_TIME DESC");
	   		example.setOrderByClause("BAOKUAN_ORDER ASC");
	   		handlePageQueryDefault(request, example);
	   		Criteria criteria = example.createCriteria();
	   		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	   		criteria.andIsBaokuanEqualTo("001");
	   		
	   		List<Product> products = productService.list(example);
	   		if( products.size()>0 ){
	   			for( Product temp : products ){
	   				ProductAndJd projd = new ProductAndJd();
	   				projd.setId(temp.getId());
	   				projd.setMainImageUrl(temp.getMainImageUrl());
	   				projd.setName(temp.getName());
	   				projd.setProductHongbao(temp.getProductHongbao());
	   				projd.setProductOrginPrice(temp.getProductOrginPrice());
	   				projd.setProductPrice(temp.getProductPrice());
	   				projd.setTotalFeedback(temp.getTotalFeedback());
	   				projd.setTotalSales(temp.getTotalSales());
	   				projd.setType("001");
	   				projds.add(projd);
	   			}
	   		}
	   		
	   		resultMap.put(DATA, projds);
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "zkindex", e.toString(),"登入折扣商城中心首页",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    
    /**
     * 登入折扣商城中心首页
     * @param categoryId 类别ID
     * @param orderType 排序类型
     * @param minMaxPrice 最小到最大的价格区间，中间用-号相隔
     * @param minMaxPrice 最小到最大的销量区间     中间用-号相隔
     * @return
     */
    @RequestMapping(value="/jingxuans")
    @ResponseBody
    public Map<String,Object> jingxuans(HttpServletRequest request,HttpServletResponse response){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		List<ProductAndJd> projds = new ArrayList<ProductAndJd>();
	   		
	   		ProductExample example = new ProductExample();
	   		example.setOrderByClause("UPDATE_TIME DESC");
	   		example.setOrderByClause("JINGPING_ORDER ASC");
	   		handlePageQueryDefault(request, example);
	   		Criteria criteria = example.createCriteria();
	   		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	   		criteria.andIsJingpingEqualTo("001");
	   		
	   		List<Product> products = productService.list(example);
	   		if( products.size()>0 ){
	   			for( Product temp : products ){
	   				ProductAndJd projd = new ProductAndJd();
	   				projd.setId(temp.getId());
	   				projd.setMainImageUrl(temp.getMainImageUrl());
	   				projd.setName(temp.getName());
	   				projd.setProductHongbao(temp.getProductHongbao());
	   				projd.setProductOrginPrice(temp.getProductOrginPrice());
	   				projd.setProductPrice(temp.getProductPrice());
	   				projd.setTotalFeedback(temp.getTotalFeedback());
	   				projd.setTotalSales(temp.getTotalSales());
	   				projd.setType("001");
	   				projds.add(projd);
	   			}
	   		}
	   		
	   		ProductJdExample example2 = new ProductJdExample();
	   		example2.setOrderByClause("UPDATE_TIME DESC");
	   		example2.setOrderByClause("JINGXUAN_ORDER ASC");
	   		handlePageQueryDefault(request, example2);
	   		com.itic.mall.system.productjd.persistence.model.ProductJdExample.Criteria criteria2 = example2.createCriteria();
	   		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
	   		criteria2.andIsJingxuanEqualTo("001");
	   		
	   		List<ProductJd> jds = productJdService.list(example2);
	   		if( jds.size()>0 ){
	   			for( ProductJd temp : jds ){
	   				ProductAndJd projd = new ProductAndJd();
	   				projd.setId(temp.getId());
	   				projd.setMainImageUrl(temp.getGoodsUrl());
	   				projd.setName(temp.getGoodsName());
	   				projd.setProductHongbao(temp.getConTicketPrice());
	   				projd.setProductOrginPrice(temp.getOriPrice());
	   				projd.setProductPrice(temp.getConPrice());
	   				projd.setTotalFeedback(RandomStringHelper.randomNumStr(3));
	   				projd.setTotalSales(temp.getTotalSales());
	   				projd.setType("002");
	   				projds.add(projd);
	   			}
	   		}
	   		
	   		resultMap.put(DATA, projds);
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "zkindex", e.toString(),"登入折扣商城中心首页",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    /**
     * APP折扣商城中心
     * @param categoryId 类别ID
     * @param orderType 排序类型
     * @param minMaxPrice 最小到最大的价格区间，中间用-号相隔
     * @param minMaxPrice 最小到最大的销量区间     中间用-号相隔
     * @return
     */
    @RequestMapping(value="/categorys")
    @ResponseBody
    public Map<String,Object> categorys(HttpServletRequest request,HttpServletResponse response){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
        	//查找相应的分类信息
        	CategoryExample categoryExample = new CategoryExample();
        	categoryExample.createCriteria().andIsEffectiveEqualTo(DBConst.TRUE);
        	List<Category> categorys = categoryService.list(categoryExample);
        	resultMap.put(DATA, categorys);
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "categorys", e.toString(),"获得商城所有商品类别信息",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    

    /**
     * 根据商品ID获得商品详情信息
     * @param categoryId 类别ID
     * @param orderType 排序类型
     * @param minMaxPrice 最小到最大的价格区间，中间用-号相隔
     * @param minMaxPrice 最小到最大的销量区间     中间用-号相隔
     * @return
     */
    @RequestMapping(value="/product")
    @ResponseBody
    public Map<String,Object> product(HttpServletRequest request,HttpServletResponse response,String productId){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		if(StringHelper.isNotBlank(productId)){
    			Map<String, Object> dataMap = new HashMap<String,Object>();
        		
        		//根据ID查找商品详情以及还有商品的SKU信息
        		Product product = productService.get(productId);
        		if( null != product ){
        			dataMap.put("product", product);
                	
            		//根据商品信息查找 商品的SKU信息
            		ProductSkuExample example = new ProductSkuExample();
            		example.setOrderByClause("IS_MAIN DESC");
            		com.itic.mall.system.productsku.persistence.model.ProductSkuExample.Criteria criteria = example.createCriteria();
            		criteria.andProductIdEqualTo(productId);
            		List<ProductSku> skus = productSkuService.list(example);
            		if( skus.size() > 0 ){
                		for( ProductSku tmp: skus ){
                			filterSkuPrice(tmp);
                		}
                	}
            		
            		dataMap.put("skus", skus);   		
                	resultMap.put(DATA, dataMap);
        			result = SUCCESS;
        			errorCode = SUCCESS_ERROR_CODE;
                	errorMsg = SUCCESS_ERROR_MSG;  	
        		}else{
        			errorCode = PRODUCT_EMPTY_ERROR_CODE;
                	errorMsg = PRODUCT_EMPTY_ERROR_MSG;  	
        		}
    		}
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "product", e.toString(),"根据商品ID获得商品详情信息",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    /**
     * 根据商品ID获得商品详情信息
     * @param categoryId 类别ID
     * @param orderType 排序类型
     * @param minMaxPrice 最小到最大的价格区间，中间用-号相隔
     * @param minMaxPrice 最小到最大的销量区间     中间用-号相隔
     * @return
     */
    @RequestMapping(value="/detail")
    @ResponseBody
    public Map<String,Object> detail(HttpServletRequest request,HttpServletResponse response,String productId,String jdId){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		if(StringHelper.isNotBlank(productId)){
    			Map<String, Object> dataMap = new HashMap<String,Object>();
        		
        		//根据ID查找商品详情以及还有商品的SKU信息
        		Product product = productService.get(productId);
        		if( null != product ){
        			dataMap.put("product", product);
                	
            		//根据商品信息查找 商品的SKU信息
            		ProductSkuExample example = new ProductSkuExample();
            		example.setOrderByClause("IS_MAIN DESC");
            		com.itic.mall.system.productsku.persistence.model.ProductSkuExample.Criteria criteria = example.createCriteria();
            		criteria.andProductIdEqualTo(productId);
            		List<ProductSku> skus = productSkuService.list(example);
            		if( skus.size() > 0 ){
                		for( ProductSku tmp: skus ){
                			filterSkuPrice(tmp);
                		}
                	}
            		
            		dataMap.put("skus", skus);   		
                	resultMap.put(DATA, dataMap);
        			result = SUCCESS;
        			errorCode = SUCCESS_ERROR_CODE;
                	errorMsg = SUCCESS_ERROR_MSG;  	
        		}else{
        			errorCode = PRODUCT_EMPTY_ERROR_CODE;
                	errorMsg = PRODUCT_EMPTY_ERROR_MSG;  	
        		}
    		}
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "product", e.toString(),"根据商品ID获得商品详情信息",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    /**
     * 获得TA名称
     * @return
     */
    @RequestMapping(value="/getTag")
    @ResponseBody
    public Map<String,Object> getTag( HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		WeixinBatchExample example2 = new WeixinBatchExample();
    		example2.setOrderByClause("REORDER ASC");
    		com.itic.mall.system.weixinbatch.persistence.model.WeixinBatchExample.Criteria criteria2 = example2.createCriteria();
    		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
    		criteria2.andTypeEqualTo("3");
    		List<WeixinBatch> list = weixinBatchService.list(example2);
    		
    		resultMap.put(DATA, list);
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "getCategoryTag", e.toString(),"获得TA名称",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    /**
     * 获得TA名称
     * @return
     */
    @RequestMapping(value="/getTagDetail")
    @ResponseBody
    public Map<String,Object> getTagDetail( HttpServletRequest request,HttpServletResponse response,String id ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		if( StringHelper.isNotBlank(id) ){
    			List<ProductAndJd> projds = new ArrayList<ProductAndJd>();
    			
    			WeixinBatch vo = weixinBatchService.get(id);
    			if( null != vo ){
    				String productJdIds = vo.getProductJdIds();
    				projds = getProductJdByIds(projds, productJdIds);
    				
    				String productIds = vo.getProductIds();
    				projds = getProductByIds(projds, productIds);
    				
    			}
    			resultMap.put(DATA, projds);
    			result = SUCCESS;
    			errorCode = SUCCESS_ERROR_CODE;
            	errorMsg = SUCCESS_ERROR_MSG;  
    		}
    		
    		
    		
    		
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	logException("MallIndexInterface", "getCategoryTag", e.toString(),"获得TA名称",e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    public List<ProductAndJd> getProductJdByIds( List<ProductAndJd> projds,String productJdIds ){
    	if( StringHelper.isNotBlank(productJdIds) ){
			String[] split = productJdIds.split(",");
			if( split.length>0 ){
				for( int i=0;i<split.length;i++ ){
					String jdid = split[i];
					ProductJd temp = productJdService.get(jdid);
					if( null != temp ){
						ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getGoodsUrl());
		   				projd.setName(temp.getGoodsName());
		   				projd.setProductHongbao(temp.getConTicketPrice());
		   				projd.setProductOrginPrice(temp.getOriPrice());
		   				projd.setProductPrice(temp.getConPrice());
		   				projd.setTotalFeedback(RandomStringHelper.randomNumStr(3));
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("002");
		   				projds.add(projd);
					} 
				}
			}
		}
    	return projds;
    }
    
    public List<ProductAndJd> getProductByIds( List<ProductAndJd> projds,String productIds ){
    	if( StringHelper.isNotBlank(productIds) ){
			String[] split = productIds.split(",");
			if( split.length>0 ){
				for( int i=0;i<split.length;i++ ){
					String id = split[i];
					Product temp = productService.get(id);
					if( null != temp ){
						ProductAndJd projd = new ProductAndJd();
		   				projd.setId(temp.getId());
		   				projd.setMainImageUrl(temp.getMainImageUrl());
		   				projd.setName(temp.getName());
		   				projd.setProductHongbao(temp.getProductHongbao());
		   				projd.setProductOrginPrice(temp.getProductOrginPrice());
		   				projd.setProductPrice(temp.getProductPrice());
		   				projd.setTotalFeedback(temp.getTotalFeedback());
		   				projd.setTotalSales(temp.getTotalSales());
		   				projd.setType("001");
		   				projds.add(projd);
					} 
				}
			}
		}
    	return projds;
    }
}